<template>
  <div>
    <van-nav-bar
      class="top"
      title="账号注册"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        placeholder="请输入账号"
        :rules="[{ required: true, message: '请输入账号' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请输入密码' }]"
      />
      <div style="margin: 16px;">
        <van-button
          square block
          type="info"
          native-type="submit"
        >注 册</van-button>
      </div>
      <router-link to="/login" style="color:#666;">已有账号？去登录~</router-link>
    </van-form>
  </div>
</template>

<script>
import { register } from '@/api/user'

export default {
  name: 'RegisterPage',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit (values) {
      await register(values)
      // console.log(data)
      // if (data.data.status) {

      // }
      this.$toast('注册成功')
      // this.$router.push('/login')
    },
    onClickLeft () {
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
div {
  font-size: 14px;
  text-align:center;
}
.top {
  background-color: #087;
  font-size: 20px;
}

</style>
